package com.situ.mall.admin.mapper;

import com.situ.mall.admin.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.situ.mall.admin.vo.UserVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author JavaWizard
 * @since 2023-09-11
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {

    //Mapper接口的方法中参数一旦数量超过1个 就必须要起名字
    //需要多个if条件查询的动态sql语句 全部放到Mapper.xml中

    //查询用户表格
    List<UserVO> list(@Param("username")String username, @Param("phoneNumber")String phoneNumber);

    //新增保存
    @Insert("insert into user(username,password,type_id,phone_number,status,avatar,create_time) values(#{username},#{password},#{typeId},#{phoneNumber},#{status},#{avatar},#{createTime})")
    void save(User user);

    //更新
    //避免user中有不传值的数据被更新成null，该语句写成动态sql
    void update(User user);

    //软删除
    @Delete("update user set status = 1 where id = #{id}")
    void delete(Integer id);

    //根据用户名查
    @Select("select * from user where username = #{username}")
    User selectByUsername(String username);

    //编辑——根据ID查询该行数据带到前台
    @Select("select * from user where id = #{id}")
    User selectById(Integer id);

    //判断是否用户名重复
    User selectByUsername1(@Param("username")String username, @Param("id")Integer id);
}
